<h1>Chi tiết booking</h1>

<h2>Thông tin khách hàng</h2>

<table class="data">
    <tr>
        <td class="grey">Mã khách</td>
        <td><?php echo $booking['Customer']['code'] ?></td>
    </tr>
    <tr>
        <td class="grey">Tên khách</td>
        <td><?php echo $booking['Customer']['full_name'] ?></td>
    </tr>
    <tr>
        <td class="grey">ĐT</td>
        <td><?php echo $booking['Customer']['telephone'] ?></td>
    </tr>
    <tr>
        <td class="grey">Email</td>
        <td><?php echo $booking['Customer']['email'] ?></td>
    </tr>
    <tr>
        <td class="grey">Địa chỉ</td>
        <td><?php echo $booking['Customer']['address'] ?></td>
    </tr>
</table>

<h2>Thông tin booking</h2>

<h3>Thông tin cơ bản</h3>

<div class="booking-info left">
    <table class="table2">
        <tr>
            <td>Ngày đặt:</td>
            <td><span class="auto"><?php echo date('d/m/y', strtotime($booking['Booking']['date'])) ?></span></td>
        </tr>
        <tr>
            <td>Địa điểm:</td>
            <td><?php echo $booking['Location']['name'] ?></td>
        </tr>
        <tr>
            <td>Khách sạn:</td>
            <td><?php echo $booking['Hotel']['name'] ?></td>
        </tr>
    </table>
        </div><!--.booking-info-->

<div class="booking-info center">
    <table class="table2">
        <tr>
            <td>Tình trạng:</td>
            <td><?php echo $booking['BookingStatus']['name'] ?></td>
        </tr>
        <tr>
            <td>Tổng đêm phòng:</td>
            <td><span class="auto"><?php echo $total_days ?></span>
            </td>
        </tr>
    </table>
        </div><!--.booking-info-->

<div class="booking-info right">
    <table class="table2">
        <tr>
            <td>Mã khách sạn:</td>
            <td><?php echo $booking['Booking']['hotel_booking_code'] ?></td>
        </tr>
        <tr>
            <td>Mã booking:</td>
            <td><span class="auto"><?php echo $booking['Booking']['alo_booking_code'] ?></span></td>
        </tr>
    </table>
        </div><!--.booking-info-->

<br class="clr" />

<hr />

<h3>Thanh toán</h3>

<table class="table2 booking-payment">
    <tr>
        <td class="wide-spacing">
            Loại tiền:
            <strong><?php echo $booking['Booking']['currency'] ?></strong>
        </td>

        <td class="wide-spacing">
             <strong><?php echo $booking['Booking']['vat'] ? 'Xuất VAT' : 'Không Xuất VAT' ?></strong>
        </td>

        <td class="wide-spacing">
            Tỷ giá ALO:
            <strong><?php echo number_format($booking['Booking']['alo_exchange_rate'], 1, '.', ',') ?></strong>
        </td>

        <td class="wide-spacing<?php echo $hide ?>">
            Tỷ giá KS:
            <strong><?php echo number_format($booking['Booking']['hotel_exchange_rate'], 1, '.', ',') ?></strong>
        </td>
    </tr>
</table>

<hr />

<h3>Thông tin chi tiết</h3>

<table class="table1 booking-detail">
    <tr>
        <th>Loại phòng</th>
        <th>Tiêu chuẩn</th>
        <th>SL</th>
        <th>Check in</th>
        <th>Check out</th>
        <th>Đơn giá</th>
        <th>Đêm</th>
        <th>Thành tiền</th>
        <th class="gross<?php echo $hide ?>">Giá gốc</th>
        <th class="gross<?php echo $hide ?>">Thành tiền</th>
        <th class="<?php echo $hide ?>"></th>
    </tr>
    <?php foreach ($booking['BookingDetail'] as $booking_detail): ?>
    <tr>
        <td align="center"><?php echo $booking_detail['type'] ?></td>
        <td align="center"><?php echo $booking_detail['quality'] ?></td>
        <td align="center"><?php echo $booking_detail['quantity'] ?></td>
        <td align="center"><?php echo preg_match('/voucher|promotion|khuyến mãi/', mb_strtolower($booking_detail['type'] . ' ' . $booking_detail['quality'])) ? '' : date('d/m/y', strtotime($booking_detail['checkin_date'])) ?></td>
        <td align="center"><?php echo preg_match('/voucher|promotion|khuyến mãi/', mb_strtolower($booking_detail['type'] . ' ' . $booking_detail['quality'])) ? '' : date('d/m/y', strtotime($booking_detail['checkout_date'])) ?></td>
        <td align="right"><?php echo number_format($booking_detail['cost'], 1, '.', ',') ?></td>
        <td align="right"><?php echo preg_match('/voucher|promotion|khuyến mãi/', mb_strtolower($booking_detail['type'] . ' ' . $booking_detail['quality'])) ? '' : $total_days ?></td>
        <td align="right"><?php echo number_format($booking_detail['price'], 1, '.', ',') ?></td>
        <td align="right" class="gross<?php echo $hide ?>"><?php echo number_format($booking_detail['original_cost'], 1, '.', ',') ?></td>
        <td align="right" class="gross<?php echo $hide ?>"><?php echo number_format($booking_detail['original_price'], 1, '.', ',') ?></td>
        <td align="right" class="<?php echo $hide ?>"></td>
    </tr>
    <?php endforeach; ?>
    <!--
    <tr class="heading">
        <th colspan="11">Loại khác</th>
    </tr>
    <tr>
        <td align="center">Khuyến mãi</td>
        <td align="center">Voucher</td>
        <td align="center">1</td>
        <td align="center">&nbsp;</td>
        <td align="center">&nbsp;</td>
        <td align="right">-10</td>
        <td align="right">1</td>
        <td align="right">-10</td>
        <td align="right" class="gross">0</td>
        <td align="right" class="gross">0</td>
        <td align="right"></td>
    </tr>
    -->
    <tr>
        <td colspan="6" align="right"><strong>Tổng tiền phòng</strong></td>
        <td align="right">USD</td>
        <td align="right"><span class="highlight"><?php echo number_format($total_price_usd, 1, '.', ',') ?></span></td>
        <td class="gross<?php echo $hide ?>">&nbsp;</td>
        <td align="right" class="gross<?php echo $hide ?>"><?php echo number_format($total_original_price_usd, 1, '.', ',') ?></td>
        <td align="right" class="profit<?php echo $hide ?>">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="6">&nbsp;</td>
        <td align="right">VND</td>
        <td align="right"><span class="highlight"><?php echo number_format($total_price_vnd, 1, '.', ',') ?></span></td>
        <td class="gross<?php echo $hide ?>">&nbsp;</td>
        <td align="right" class="gross<?php echo $hide ?>"><?php echo number_format($total_original_price_vnd, 1, '.', ',') ?></td>
        <td align="right" class="profit<?php echo $hide ?>"><?php echo number_format($profit_vnd, 1, '.', ',') ?></td>
    </tr>
</table>

<h3>Bao gồm</h3>
<div class="pb20">
    <?php echo $booking['Booking']['includes']; ?>
</div>
<br class="clr" />

<div id="booking-cancel">
        <h3>Điều kiện hủy phòng</h3>

    <table class="table2">
        <tr>
            <td>Không phạt tiền <span class="compulsory">*</span></td>
            <td><?php echo $booking['Booking']['cancel_0']; ?>&nbsp;ngày</td>
        </tr>
        <tr>
            <td>Phạt 50% <span class="compulsory">*</span></td>
            <td><?php echo $booking['Booking']['cancel_50']; ?>&nbsp;ngày</td>
        </tr>
        <tr>
            <td>Phạt 100% <span class="compulsory">*</span></td>
            <td><?php echo $booking['Booking']['cancel_100']; ?>&nbsp;ngày</td>
        </tr>
    </table>
        </div>

<div id="booking-payment">
        <h3>Tình trạng thanh toán</h3>

    <table class="table1 booking-detail">
        <tr>
            <th>Tiến trình</th>
            <th>Ngày</th>
            <th>Tiền</th>
            <th>Phương thức</th>
            <th>Ghi chú</th>
        </tr>
        <tr>
            <td>Đặt cọc</td>
            <td><?php echo date('d/m/y', strtotime($booking['Booking']['alo_prepaid_date'])) ?></td>
            <td><?php echo number_format($booking['Booking']['alo_prepaid_amount'], 1, '.', ',') ?></td>
            <td><?php echo $alo_prepaid_payment_type['PaymentType']['name'] ?></td>
            <td><?php $booking['Booking']['alo_prepaid_note'] ?></td>
        </tr>
        <tr>
            <td>Thu hết</td>
            <td><?php echo date('d/m/y', strtotime($booking['Booking']['alo_fullcharge_date'])) ?></td>
            <td><?php echo number_format($booking['Booking']['alo_fullcharge_amount'], 1, '.', ',') ?></td>
            <td><?php echo $alo_fullcharge_payment_type['PaymentType']['name'] ?></td>
            <td><?php $booking['Booking']['alo_fullcharge_note'] ?></td>
        </tr>
        <tr>
            <td>KS thu</td>
            <td><?php echo date('d/m/y', strtotime($booking['Booking']['hotel_charge_date'])) ?></td>
            <td><?php echo number_format($booking['Booking']['hotel_charge_amount'], 1, '.', ',') ?></td>
            <td></td>
            <td><?php $booking['Booking']['hotel_charge_note'] ?></td>
        </tr>
        <tr class="secondary<?php echo $hide ?>">
            <td>Deposit ks</td>
            <td><?php echo date('d/m/y', strtotime($booking['Booking']['hotel_prepaid_date'])) ?></td>
            <td><?php echo number_format($booking['Booking']['hotel_prepaid_amount'], 1, '.', ',') ?></td>
            <td><?php echo $hotel_prepaid_payment_type['PaymentType']['name'] ?></td>
            <td><?php $booking['Booking']['hotel_prepaid_note'] ?></td>
        </tr>
        <tr class="secondary<?php echo $hide ?>">
            <td>T/T hết cho KS</td>
            <td><?php echo date('d/m/y', strtotime($booking['Booking']['hotel_fullcharge_date'])) ?></td>
            <td><?php echo number_format($total_original_price_vnd - $booking['Booking']['hotel_prepaid_amount'], 1, '.', ',') ?></td>
            <td><?php echo $hotel_fullcharge_payment_type['PaymentType']['name'] ?></td>
            <td><?php $booking['Booking']['hotel_fullcharge_note'] ?></td>
        </tr>
    </table>
</div>

<br class="clr" />

<div id="action-bar">
    <div class="action-bar-group">
        <input id="edit_booking" name="" type="button" class="button" value="Sửa booking" onclick="process_toolbar(this);" />
        <input id="confirm_vi" name="" type="button" class="button" value="Confirm khách - VI" onclick="process_toolbar(this);" />
        <input id="confirm_en" name="" type="button" class="button" value="Confirm khách - EN" onclick="process_toolbar(this);" />
        <?php if (empty($hide)): ?>
        <input id="send_booking" name="" type="button" class="button" value="Gửi booking" onclick="process_toolbar(this);" />
        <?php endif; ?>
    </div>

    <div class="action-bar-group">
        <?php echo $this->Form->input('Booking.booking_status_id', array('type' => 'select', 'class' => 'dropdown', 'label' => false, 'div' => false)); ?>
        <input id="change_booking_status" name="" type="button" class="button" value="Cập nhật" onclick="process_toolbar(this);" />
    </div>

    <div class="action-bar-group right">
        <?php echo $this->Form->submit('Quay lại', array('class' => 'button', 'onclick' => "return back_to_index()", 'div' => false)); ?>
        <script type="text/javascript">
        function back_to_index()
        {
            window.location = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'index')) ?>';
            return false;
        }
        </script>
    </div>
    <br class="clr" />
</div>
<script type="text/javascript">
function process_toolbar(source)
{
    var source_id = $(source).attr('id');
    if (source_id == 'edit_booking')
    {
        var url = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'edit', $booking['Booking']['id'])) ?>';
        window.location = url;
    }

    if (source_id == 'confirm_vi')
    {
        var url = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'send', $booking['Booking']['id'], 'confirm/lang:vi')) ?>';
        window.location = url;
    }

    if (source_id == 'confirm_en')
    {
        var url = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'send', $booking['Booking']['id'], 'confirm/lang:en')) ?>';
        window.location = url;
    }

    if (source_id == 'send_booking')
    {
        var url = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'send', $booking['Booking']['id'], 'send_booking')) ?>';
        window.location = url;
    }

    if (source_id == 'change_booking_status')
    {
        var url = '<?php echo $this->Html->url(array('controller' => 'bookings', 'action' => 'show', $booking['Booking']['id'], 'action:change_booking_status', 'status:')) ?>' + $('#BookingBookingStatusId').val();
        window.location = url;
    }
}
</script>